<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'base.categories.class.php');

class BaseCategoriesHTMLBase extends BaseCategoriesBase {
	
	//constructor
	function BaseCategoriesHTMLBase() {
		parent::BaseCategoriesBase();
	}
	
	//methods	
	//
	//
	function getCategoriesHTML_JSCOOKMENU($parent = 0, $front = true, $level = 0) {
		$items = $this->getCategoriesSubs($parent);
		$html = "";
		
		if( $level == 0 ) {
			global $LANGUAGE;
			$html .= '<div id="topmenu_jscookmenu"></div>';
			$html .= "<script type=\"text/javascript\">" . "\n";
			$html .= "<!--" . "\n";
			$html .= "var jscook_Menu = " . "\n";
			$html .= "[" . "\n";
			$html .= "	['', '" . $LANGUAGE['Home'] . "', '" . CONFIG_URL_HTTP . "', '', ''], " . "\n";
		}
		if( is_array($items) && sizeof($items) > 0 ) {
			for($i=0, $n=sizeof($items); $i<$n; $i++) {
				if( $items[$i]['categories_menushow'] != '1' ) {
					continue;
				}
				$title = $items[$i]['categories_name'];
				$link = CONFIG_URL_HTTP . 'c/' . $items[$i]['categories_link'];
				$target = $items[$i]['categories_target'];
				$description = '';
				
				$itemsubs = $this->getCategoriesSubs($items[$i]['categories_id']);
				if( sizeof($itemsubs) > 0 ) {
					$link = '';
				}
				$html .= "	['', '" . $title . "', '" . $link . "', '" . $target . "', '" . $description . "'";
				
				if( $items[$i]['categories_id'] > 0 ) {
					$html .= "," . "\n";
					$html .= $this->getCategoriesHTML_JSCOOKMENU($items[$i]['categories_id'], true, $level+1);
					$html .= "]," . "\n";
				} else {
					$html .= "]," . "\n";
				}
			}
		}
		
		if( $level == 0 ) {
			//$html .= "	['', '', '', '', ''], " . "\n";
			$html .= "];" . "\n";
			$html .= 'cmDraw (\'topmenu_jscookmenu\', jscook_Menu, \'hbr\', cmThemeLugou);' . "\n";
			$html .= "-->" . "\n";
			$html .= "</script>" . "\n";
		}
		
		return $html;
	}
	
	function getCategoriesHTML_Struct($parent = '0', $front = false, $level = 0) {
		$items = $this->getCategoriesSubs($parent);
		$html = "";
		
		if( is_array($items) ) {
			if( $front == true ) {
				if( $level == 0 ) {
					global $LANGUAGE;
					
					$html .= '<ul class="h">' . "\n";
					$html .= '<li id="n0"><a href="' . CONFIG_URL_HTTP . '">' . $LANGUAGE['Home'] . '</a></li>' . "\n";
				} else {
					$html .= '<ul class="hs" style="display: none; ">' . "\n";
					//$html .= '<ul class="hs" style="visibility: hidden; ">' . "\n";
				}
			} else {
				//$html .= '<ul style="display: none; ">' . "\n";
				//$html .= '<ul style="visibility: hidden; ">' . "\n";
				//
				if( $level == 0 ) {
					$html .= '<ul class="mh">' . "\n";
				} else {
					$html .= '<ul class="mvs">' . "\n";
				}
			}
			for($i=0, $n=sizeof($items); $i<$n; $i++) {
				if( $items[$i]['categories_menushow'] != '1' ) {
					continue;
				}
				if( $front == true ) {
					if( $level == 0 ) {
						$html .= '<li id="n' . ($i+1) . '">';
					} else {
						$html .= '<li>';
					}
					$html .= '<a href="' . CONFIG_URL_HTTP . 'c/' . $items[$i]['categories_link'] . '">';
					$html .= $items[$i]['categories_name'] ? $items[$i]['categories_name'] : ' ';
					$html .= '</a>';
				} else {
					$html .= "<li id='m" . $items[$i]['categories_id'] . "' aid='" . $items[$i]['categories_id'] . "' aparent='" . $items[$i]['categories_parent'] . "' aname='" . $items[$i]['categories_name'] . "' alink='" . $items[$i]['categories_link'] . "' atext='" . $items[$i]['categories_text'] . "' atitle='" . $items[$i]['categories_title'] . "' acode='" . $items[$i]['categories_code'] . "' adescription='" . $items[$i]['categories_description'] . "'>";
					$html .= ($items[$i]['categories_name'] ? $items[$i]['categories_name'] : ' ');
				}
				if( $items[$i]['categories_id'] > 0 ) {
					$html .= $this->getCategoriesHTML_Struct($items[$i]['categories_id'], $front, $level+1);
				}
				$html .= '</li>' . "\n";
			}
			$html .= '</ul>' . "\n";
		}
		
		return $html;
	}
}
//
?>